package com.jvm123.blog.controller.rest

import com.jvm123.blog.entity.Post
import com.jvm123.blog.service.PostService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 *
 * @author yawn http://jvm123.com
 *     2019/11/30 15:18
 */
@RestController("restPostController")
@RequestMapping("rest/post")
class PostController {

    @Autowired
    PostService postService

    // data 模块
    @GetMapping("{id}")
    Post get(@PathVariable("id") long id) {
        postService.findOne(id)
    }

    @PostMapping("batch")
    List<Post> batch(@RequestBody Map<String, Integer> param) {
        Long offset = param.get("offset")
        if (offset != null && offset > 0) {
            return postService.batch(offset)
        }
        int page = param.get("page")
        int size = param.get("size")
        postService.batch(page, size)
    }
}
